package com.zjitc;

import com.zjitc.Mapper.UserMapper;
import javax.sql.DataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.mapper.MapperFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/3/8 14:48
 * @description:
 */
@SuppressWarnings("ALL")
@Configuration
@Import(DataSourceConfig.class)
@MapperScan("classpath:")

public class SpringMybatisConfig {

    @Bean(name = "SqlSessionFactory")
    public SqlSessionFactoryBean  createSessionFactory(DataSource dataSource) throws Exception {
      SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
      factoryBean.setDataSource(dataSource);
      return factoryBean;
    }



    @Bean(name = "UserMapper")
    public MapperFactoryBean<UserMapper> usermapper(SqlSessionFactory sqlSessionFactory){
      MapperFactoryBean<UserMapper> mapperFactoryBean  = new MapperFactoryBean<UserMapper>(UserMapper.class);
      mapperFactoryBean.setSqlSessionFactory(sqlSessionFactory);
      return mapperFactoryBean;
    }
}
